package com.mybatis_stu.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.mybatis_stu.mapper.StudentMapper;
import com.mybatis_stu.pojo.PageBean;
import com.mybatis_stu.pojo.Student;
import com.mybatis_stu.service.StudentService;
import lombok.extern.java.Log;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @Package com.mybatis_stu.service.impl
 * @Date 2024/12/15 21:26
 */
@Slf4j
@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentMapper studentMapper;
    @Override
    public void add(Student student) {
        //补全部门数据

        student.setUpdateTime(LocalDateTime.now());
        //调用持久层增加功能
        studentMapper.insert(student);
    }

    @Override
    public void delete(List<Integer> ids) {
        studentMapper.delete(ids);
    }

    @Override
    public void update(Student student) {
        student.setUpdateTime(LocalDateTime.now()); //更新修改时间为当前时间

        studentMapper.update(student);
    }

    @Override
    public PageBean page(Integer page, Integer pageSize, String name,Integer educationId, Integer classId, String number) {
        //设置分页参数
        PageHelper.startPage(page, pageSize);
        //执行条件分页查询
        List<Student> studentList = studentMapper.list(name, educationId,  classId, number);
        //获取查询结果
        Page<Student> p = (Page<Student>) studentList;
        //封装PageBean
        PageBean pageBean = new PageBean(p.getTotal(), p.getResult());
        return pageBean;
    }

    @Override
    public void discipline(Integer studentId, Integer score) {
        // 更新违纪信息
        studentMapper.updateDiscipline(studentId, score);
    }


}
